﻿using System;
using System.Web;
using System.Web.UI;
using Microsoft.Practices.Unity;

namespace TSharp.Core.Web
{
    /// <summary>
    /// TSharp.Core.Web 所有用户控件基类
    /// <para>by tangjingbo at 2009-12-25 13:11</para>
    /// </summary>
    public abstract class AopBaseUserControl : UserControl
    {
        /// <summary>
        /// 重写初始化方法，加入ioc注入
        /// </summary>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            OnRegsiterMessage();
            InjectDependencies();
        }

        /// <summary>
        /// 注册消息的方法
        /// </summary>
        public virtual void OnRegsiterMessage()
        {
        }


        /// <summary>
        /// Ico 注入
        /// </summary>
        protected virtual void InjectDependencies()
        {
            IUnityContainer container = AopContext.Default;
            if (container == null)
                throw new InvalidOperationException(Resource.NoRequestContainer);
            container.BuildUp(GetType(), this);
        }
    }
}